Anim GIF Library
Anim GIF Library is a small but powerful DLL for use in Win32 and Win64 software, it returns all the animated GIF's frame pictures.
Most of all the library is thread-safe.
Also there is a mass loading functionality based on a FIFO list and a thread pool.
Just add a GIF frames request to the library and the threads extract and process the request one-by-one and return the frames in a callback.
Optionally resize, add shadow effect, or film frame to the output frames using Professional Thumbnailer Library.
- All the frames are returned as HBitmap picture handles
- High quality resize if needed
- Full multi-threading support, so as fast as reasonably possible
- Accepts 3 inputs: file name, PIDL and in-memory "GIF files"
- Options to add configurable shadow effect, and film frame effect (both at the same time) with the help of Professional Thumbnailer Library if needed
- Advanced quantization support using Free Image Library's "Xiaolin Wu color" and "NeuQuant neural-net" quantization algorithms
- Each thumbnail request has its own parameters
- Create and save animated GIF files
- Delphi and C++ header included
The component can be evaluated freely. If you like it and decide to use it in a freeware, shareware or commercial (or any other money making - advertising, in app. selling, etc.) product one of the licenses is needed.
Basic usage
1. Create an instance with:
2. Add request(s) with:
- AnimGIF_AddFileName()
- AnimGIF_AddPIDL()
- AnimGIF_AddMemory()
The 'TAnimGIFParameters.Callback' must be specified else the create function will fail.
If the functions return 'False' do not forget to free any 'User' etc. objects - normally free them eg. in the callback.
These are non-blocking calls, once a request has been added to the queue these functions return and the threads will process the requests and return the frame handles in the callback as fast as possible.
The callback is called from the worker threads so be aware that the callback code is running in a separate thread and also the specific worker thread is paused until the callback returns.
3. Free the instance if finished with:
To cancel all the added requests call:
Note that this will not cancel the jobs currently processing just clears the job list.
The callback may (and surely will) still return previously requested stuff, use the parameters returned to check if the request is from a previous or current listing, eg. use the 'User' parameter.
There are 3 simple blocking functions to request the frames without threading:
- AnimGIF_GetGIFFileNameFrames()
- AnimGIF_GetGIFPIDLFrames()
- AnimGIF_GetGIFMemoryFrames()
It's safe to call these functions in threads too though.
When setting 'Width' and 'Height' to '0' the original dimension sized bitmaps are returned. Setting these parameters to a non-zero value results that the frames are resized in full 32 bit ARGB (as a GIF is max. 256 colors resizing happens in full 32 bits mode, results ~16 million colors) with a high quality Lanczos filter. Aspect ratio is preserved.
Setting 'StrictDimensions' to 'True' results that the returned bitmaps are exactly 'Width' and 'Height' sized with the image centered.
Optionally Professional Thumbnailer Library ('ProfessionalThumbnailer.dll') can be used to add eg. a shadow effect for the returned images. Add to the uses list 'ProfessionalThumbnailerDefs' and fill in a 'TPTAddParameters' struct and pass it in 'PTAddParameters'. Note that this requires 'ProfessionalThumbnailer.dll' beside your .exe.
Example with default parameters:
var
AddParameters: TPTAddParameters;
begin
ZeroMemory(@AddParameters, SizeOf(TPTAddParameters));
AddParameters.Width := 300;
AddParameters.Height := 300;
AddParameters.KeepAspectRatio := True;
AddParameters.DontResizeSmaller := True;
AddParameters.StrictDimensions := False; //* Returned thumbnails will be always AddParameters.Width x AddParameters.Height, picture centered
AddParameters.Resampler := 0; //* Lanczos
AddParameters.ThumbnailType := PT_TYPE_BITMAP;
AddParameters.Shadow := PT_SHADOW_YES;
AddParameters.ShadowX := 2;
AddParameters.ShadowY := 2;
AddParameters.ShadowType := PT_SHADOW_ALPHA;
AddParameters.ShadowBlur := 13.0;
AddParameters.ShadowIntensity := 174;
AddParameters.FilmFrame := PT_FILMFRAME_NO;
AddParameters.AspectRatio := PT_ASPECT_RATIO_AUTOMATIC;
Note: This 'TPTAddParameters' struct needs to be valid until the actual frames are returned, so declare it as a global variable if using the multi-threaded functions.
Note: If the animation is flickering set the form's 'DoubleBuffered' property to 'True'.
Note: As GDI HBitmap handles are returned, there is a limit of around 10 000 handles, that means max. 10 000 picture frames can be extracted.
Convert the HBitmap handle pictures into a custom buffer when they arrive if more than that much frames are needed.
In Delphi Graphics32 can used with a 'TBitmap32' bitmap that uses 'TMemoryBackend' for the buffer, assign the received frames to these 'TBitmap32' bitmaps and free the handle with 'DeleteObject(BitmapHandle)' to omit the limitation.
|